package com.lechi.web.controller;

import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import com.lechi.web.common.annotation.Anonymous;
import com.lechi.web.common.config.LeChiConfig;
import com.lechi.web.common.constant.HttpStatus;
import com.lechi.web.common.core.controller.BaseController;
import com.lechi.web.common.core.domain.AjaxResult;
import com.lechi.web.common.core.page.PageDomain;
import com.lechi.web.common.core.page.TableDataInfo;
import com.lechi.web.common.core.page.TableSupport;
import com.lechi.web.common.enums.ErrorCodeEnum;
import com.lechi.web.common.exception.ServiceException;
import com.lechi.web.common.utils.DateUtils;
import com.lechi.web.common.utils.StringUtils;
import com.lechi.web.common.utils.http.HttpUtils;
import com.lechi.web.common.utils.sql.SqlUtil;
import com.lechi.web.constants.Constants;
import com.lechi.web.service.IIotMonitorDataService;
import com.lechi.web.service.IIotSensorRecordService;
import com.lechi.web.system.domain.*;
import com.lechi.web.vo.IotAnalysisDataQueryVo;
import com.lechi.web.vo.IotMonitorDataExportVo;
import com.lechi.web.vo.IotMonitorDataQueryVo;
import com.lechi.web.vo.IotMonitorExportResultVo;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

/**
 * 监测数据Controller
 *
 * @author yangguang
 */
@Slf4j
@RestController
@RequestMapping("/iot/data")
@RequiredArgsConstructor
public class IotMonitorDataController extends BaseController {

    private final IIotMonitorDataService iotMonitorDataService;

    @Autowired
    private IIotSensorRecordService iIotSensorRecordService;
    private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 创建标题样式
     *
     * @param workbook 工作簿对象
     * @return 标题样式
     */
    private static CellStyle createTitleStyle(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        Font font = workbook.createFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short) 14); // 大字体
        font.setBold(true);
        font.setColor(IndexedColors.BLACK.getIndex());
        style.setFont(font);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        return style;
    }

    /**
     * 创建列头样式
     *
     * @param workbook 工作簿对象
     * @return 列头样式
     */
    private static CellStyle createHeaderStyle(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        Font font = workbook.createFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short) 12); // 合适大小字体

        font.setColor(IndexedColors.BLACK.getIndex());
        style.setFont(font);
        style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        return style;
    }

    /**
     * 要素历史查询数据列表
     *
     * @param iotMonitorDataQueryVo the iot monitor data query vo
     * @return the table data info
     */
    @Anonymous
    @GetMapping("/list")
    //    @PreAuthorize("@ss.hasPermi('iot:cmd:query')")
    public TableDataInfo list(IotMonitorDataQueryVo iotMonitorDataQueryVo) {
        startPage();
        // 获取当前的用户名称
        IotMonitorDataBo iotMonitorDataBo = new IotMonitorDataBo();
        BeanUtils.copyProperties(iotMonitorDataQueryVo, iotMonitorDataBo);
        iotMonitorDataBo.setTableName(Constants.MONITOR_DATA_TABLE + iotMonitorDataQueryVo.getDeviceId());
        List<IotMonitorDataBo> list = iotMonitorDataService.selectIotMonitorDataList(iotMonitorDataBo);
        return getDataTable(list);
    }

    /**
     * 查询监测数据列表
     *
     * @param iotMonitorDataQueryVo the iot monitor data query vo
     * @return the table data info
     */
//    @Log(title = "查询监测数据列表导出", businessType = BusinessType.UPDATE)
    @GetMapping("/downloader")
//    @PreAuthorize("@ss.hasPermi('iot:cmd:query')")
    public TableDataInfo downloader(@Valid IotMonitorDataQueryVo iotMonitorDataQueryVo) {
        LocalDateTime beginTime = LocalDateTime.parse(iotMonitorDataQueryVo.getParams().get("beginTime").toString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
        LocalDateTime endTime = LocalDateTime.parse(iotMonitorDataQueryVo.getParams().get("endTime").toString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
        if (!beginTime.isBefore(endTime)) {
            throw new ServiceException(ErrorCodeEnum.DATE_TIME_ERROR.getValue(), ErrorCodeEnum.DATE_TIME_ERROR.getKey());
        }
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("tableName", Constants.MONITOR_DATA_TABLE + iotMonitorDataQueryVo.getDeviceId());
        paramMap.put("timeFormat", getTimeFormat(iotMonitorDataQueryVo.getInternalType().trim()));
        paramMap.put("sensorAliasId", iotMonitorDataQueryVo.getSensorAliasId());
        LocalDateTime queryTime = "second".equals(iotMonitorDataQueryVo.getInternalType()) || iotMonitorDataQueryVo.getQueryType() == 1 ? beginTime : beginTime.plusMinutes(1);
        paramMap.put("beginTime", queryTime);
        paramMap.put("endTime", endTime);
        paramMap.put("internalTime", iotMonitorDataQueryVo.getInternalTime());
        paramMap.put("internalType", iotMonitorDataQueryVo.getInternalType());
        paramMap.put("queryType", iotMonitorDataQueryVo.getQueryType());
        Map<String, IotSensorValue> sensorValueMap = iotMonitorDataService.formatTimeExportMonitorData(iotMonitorDataQueryVo, paramMap);
        List<IotMonitorExportResultVo> list = Lists.newArrayList();
        if (sensorValueMap == null || sensorValueMap.isEmpty()) {
            return getDataTable(list);
        }
        long total = getInternalNum(iotMonitorDataQueryVo, beginTime, endTime);
        int start = iotMonitorDataQueryVo.getQueryType() == 1 ? "hour".equals(iotMonitorDataQueryVo.getInternalType()) ? 1: 0 : 1;
        for (int i = start; i <= (total > 1048575 ? 1048575 : total); i = i + 1) {
            String dateTime = getInternalTime(iotMonitorDataQueryVo, beginTime, i);
            IotMonitorExportResultVo resultVo = new IotMonitorExportResultVo();
            resultVo.setT(dateTime);
            IotSensorValue iotSensorValue = sensorValueMap.get(dateTime) == null ? sensorValueMap.get("'" + dateTime + "'") : sensorValueMap.get(dateTime);
            resultVo.setV(iotSensorValue == null ? "" : iotSensorValue.getV());
            list.add(resultVo);
        }
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(list.size());
        return rspData;
    }

    private long getInternalNum(IotMonitorDataQueryVo monitorDataQueryVo, LocalDateTime beginDay, LocalDateTime endDay) {
        long internalValue = monitorDataQueryVo.getInternalTime() == null ? 1 : monitorDataQueryVo.getInternalTime();
        return switch (monitorDataQueryVo.getInternalType()) {
            case "year" -> Duration.between(beginDay, endDay).toDays() / 365;
            case "month" -> Duration.between(beginDay, endDay).toDays() / 30;
            case "day" -> Duration.between(beginDay, endDay).toDays() / internalValue;
            case "hour" -> Duration.between(beginDay, endDay).toHours() / internalValue;
            case "minute" -> Duration.between(beginDay, endDay).toMinutes() / internalValue;
            case "second" -> Duration.between(beginDay, endDay).toSeconds();
            default -> throw new IllegalStateException("Unexpected value: " + monitorDataQueryVo.getInternalType());
        };
    }

    private String getInternalTime(IotMonitorDataQueryVo monitorDataQueryVo, LocalDateTime beginDay, int i) {
        long internalValue = monitorDataQueryVo.getInternalTime() == null ? 1 : monitorDataQueryVo.getInternalTime();
        return switch (monitorDataQueryVo.getInternalType()) {
            case "years" -> beginDay.plusYears(i).toString().substring(0, 4);
            case "month" -> beginDay.plusMonths(i).toString().substring(0, 7);
            case "day" ->
                    beginDay.plusDays(internalValue * i).withMinute(0).withSecond(0).format(formatter);
            case "hour" -> beginDay.plusHours(internalValue * i).withMinute(0).withSecond(0).format(formatter);
            case "minute" -> beginDay.plusMinutes(internalValue * i).format(formatter);
            case "second" -> beginDay.plusSeconds(i).format(formatter);
            default -> throw new IllegalStateException("Unexpected value: " + monitorDataQueryVo.getInternalType());
        };
    }

    private String getTimeFormat(String internalType) {
        return switch (internalType) {
            case "years" -> "'%Y'";
            case "month" -> "'%Y-%m'";
            case "day", "hour" -> "'%Y-%m-%d %H:00:00'";
            case "minute" -> "'%Y-%m-%d %H:%i:00'";
            case "second" -> "'%Y-%m-%d %H:%i:%s'";
            default -> throw new IllegalStateException("Unexpected value: " + internalType);
        };
    }

    /**
     * 获取传感器数据
     *
     * @param deviceId the deviceSn
     * @return the data
     */
    @Anonymous
    @GetMapping("/getdata/{deviceId}")
    public TableDataInfo new1(@PathVariable("deviceId") String deviceId) {
        IotMonitorDataBo iotMonitorDataBo = new IotMonitorDataBo();
        iotMonitorDataBo.setTableName(Constants.MONITOR_DATA_TABLE + deviceId);
        List<IotMonitorDataBo> list = iotMonitorDataService.selectLatestMonitorData(iotMonitorDataBo);
        return getDataTable(list);
    }

    /**
     * 查询监测数据列表
     *
     * @param iotAnalysisDataQueryVo the iot monitor data query vo
     * @return the table data info
     */
    @PostMapping("/dataAnalysis")
    public AjaxResult dataAnalysis(@RequestBody @Valid IotAnalysisDataQueryVo iotAnalysisDataQueryVo) {
        LocalDateTime beginTime = iotAnalysisDataQueryVo.getBeginTime();
        LocalDateTime endTime = iotAnalysisDataQueryVo.getEndTime();
        if (!beginTime.isBefore(endTime)) {
            throw new ServiceException(ErrorCodeEnum.DATE_TIME_ERROR.getValue(), ErrorCodeEnum.DATE_TIME_ERROR.getKey());
        }

        Map<Object, List<IotSensorValue>> map = Maps.newHashMap();
        var list = JSON.parseObject(iotAnalysisDataQueryVo.getSensors(), List.class);
        List<CompletableFuture<Void>> futureList = Lists.newArrayList();
        for (Object object : list) {
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("tableName", Constants.MONITOR_DATA_TABLE + iotAnalysisDataQueryVo.getDeviceId());
            paramMap.put("timeFormat", getTimeFormat(iotAnalysisDataQueryVo.getInternalType().trim()));
            paramMap.put("beginTime", beginTime.plusMinutes(1));
            paramMap.put("endTime", endTime);
            paramMap.put("internalTime", 1);
            paramMap.put("internalType", iotAnalysisDataQueryVo.getInternalType().trim());
            JSONObject sensors = (JSONObject) object;
            paramMap.put("queryType", sensors.get("queryType"));
            paramMap.put("sensorAliasId", sensors.get("sensorAliasId"));
            futureList.add(CompletableFuture.supplyAsync(() -> iotMonitorDataService.selectDataAnalysisData(paramMap))
                    .thenAccept(sensorValueList -> {
                        map.put(paramMap.get("sensorAliasId"), sensorValueList);
                    }));
        }
        // 使用allOf等待所有CompletableFuture完成，它返回一个CompletableFuture<Void>
        CompletableFuture<Void> allFutures = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
        allFutures.join();
        return success(map);
    }

    /**
     * 查询监测数据列表
     *
     * @param iotMonitorDataQueryVo the iot monitor data query vo
     * @return the ajax result
     */
    @GetMapping("/count")
    //    @PreAuthorize("@ss.hasPermi('iot:cmd:query')")
    public AjaxResult count(IotMonitorDataQueryVo iotMonitorDataQueryVo) {
        IotMonitorDataBo iotMonitorDataBo = new IotMonitorDataBo();
        BeanUtils.copyProperties(iotMonitorDataQueryVo, iotMonitorDataBo);
        iotMonitorDataBo.setTableName(Constants.MONITOR_DATA_TABLE + iotMonitorDataQueryVo.getDeviceId());
        IotMonitorDataCountBo iotMonitorDataCount = iotMonitorDataService.selectIotMonitorDataCount(iotMonitorDataBo);
        return AjaxResult.success(iotMonitorDataCount);
    }

    /**
     * 获取临潼站数据
     *
     * @return the lc 001
     */
    @Anonymous
    @GetMapping("/getLC001")
    public AjaxResult getLC001() {
        final String deviceLC001 = HttpUtils.sendSSLPost("https://www.dtuip.com/queryUserAllSensorDatas.htm", "userId=93065&deviceIds=251835");
        final JSONObject deviceJSON1 = JSON.parseObject(deviceLC001);
        final JSONArray senLastDataList = deviceJSON1.getJSONArray("senLastDataList");
        return getResult(senLastDataList);
    }

    /**
     * 获取临潼站数据
     *
     * @return the lc 002
     */
    @Anonymous
    @GetMapping("/getLC002")
    public AjaxResult getLC002() {
        final String deviceLC002 = HttpUtils.sendSSLPost("https://www.dtuip.com/queryUserAllSensorDatas.htm", "userId=93065&deviceIds=275600");
        final JSONObject deviceJSON2 = JSON.parseObject(deviceLC002);
        final JSONArray senLastDataList = deviceJSON2.getJSONArray("senLastDataList");
        return getResult(senLastDataList);
    }

    /**
     * 获取临潼站数据
     *
     * @return the lc 002
     */
    @Anonymous
    @GetMapping("/getXY")
    public AjaxResult getCity() {
        return getData(106186L, 331408L);
    }

    @Anonymous
    @GetMapping("/getData/{userId}/{deviceId}")
    public AjaxResult getData(@PathVariable("userId") Long userId, @PathVariable("deviceId") Long deviceId) {
        Optional<JSONArray> senLastDataList = Optional.of(HttpUtils.sendSSLPost("https://www.dtuip.com/queryUserAllSensorDatas.htm", "userId=" + userId + "&deviceIds=" + deviceId))
                .map(JSON::parseObject).map(deviceJSON -> deviceJSON.getJSONArray("senLastDataList"));
        return getResult(senLastDataList.orElse(new JSONArray()));
    }

    /**
     * Gets result.
     *
     * @param senLastDataList the sen last data list
     * @return the result
     */
    @NotNull
    public AjaxResult getResult(JSONArray senLastDataList) {
        List<JSONObject> jsonObjectList = Lists.newArrayList();
        senLastDataList.forEach(sensor -> {
            JSONObject sensorObj = (JSONObject) sensor;
            JSONObject target = new JSONObject();
            final Object sensorId = sensorObj.get("sensorId");
            // 4291312最后计算时间的排除掉 4782480
            if (!"4291312".equals(sensorId) && !"4782480".equals(sensorId)) {
                target.put("sensorId", sensorId);
                target.put("val", sensorObj.get("val"));
//                target.put("unit", SendSensorDataJob.map.getOrDefault("unit_" + sensorId, String.valueOf(sensorObj.get("unit"))));
//                target.put("name", SendSensorDataJob.map.get(sensorId));
                jsonObjectList.add(target);
            }
        });
        return AjaxResult.success(jsonObjectList);
    }

    /**
     * 导出监测数据列表
     *
     * @param response         the response
     * @param iotMonitorDataVo the iot monitor data vo
     */
    @PostMapping("/export")
    //    @PreAuthorize("@ss.hasPermi('iot:cmd:query')")
    public void export(HttpServletResponse response, @RequestBody IotMonitorDataExportVo iotMonitorDataVo) throws IOException {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        if (pageNum == null || pageSize == null) {
            pageNum = 1;
            pageSize = 50000;
        }
        if (pageSize > 50000) {
            throw new ServiceException(ErrorCodeEnum.PAGE_SIZE_ERROR.getValue(), ErrorCodeEnum.PAGE_SIZE_ERROR.getKey());
        }
        String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
        Boolean reasonable = pageDomain.getReasonable();
        PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);

        IotMonitorDataBo iotMonitorDataBo = new IotMonitorDataBo();
        BeanUtils.copyProperties(iotMonitorDataVo, iotMonitorDataBo);
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("beginTime", iotMonitorDataVo.getBeginTime());
        hashMap.put("endTime", iotMonitorDataVo.getEndTime());
        iotMonitorDataBo.setDeviceId(iotMonitorDataVo.getDeviceId());
        iotMonitorDataBo.setParams(hashMap);
        iotMonitorDataBo.setTableName(Constants.MONITOR_DATA_TABLE + iotMonitorDataVo.getDeviceId());
        iotMonitorDataBo.setSensorAliasId(iotMonitorDataVo.getSensorAliasId());
        Optional<IotMonitorDataBo> optional = Optional.ofNullable(iotMonitorDataService.exportIotMonitorHeader(iotMonitorDataBo));
        String titleName = optional.map(dataBo -> dataBo.getDoubleValue() + "-" + dataBo.getSensorAliasName()
                + "(" + dataBo.getQualityCode() + " 单位:" + dataBo.getUnit() + ")").orElse("");
        String sheetName = optional.map(dataBo -> dataBo.getSensorAliasName() + "监测数据").orElse("");
        List<IotMonitorDataBo> list = iotMonitorDataService.exportIotMonitorDataList(iotMonitorDataBo);
        if (list == null || list.isEmpty()) {
            throw new ServiceException(ErrorCodeEnum.NOEXITS_ERROR.getValue(), ErrorCodeEnum.NOEXITS_ERROR.getKey());
        }
        generateExcel(response, sheetName, titleName, list);
    }

    private void generateExcel(HttpServletResponse response, String sheetName, String titleName, List<IotMonitorDataBo> exportList) throws IOException {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet(sheetName);
        Row headerRow = sheet.createRow(0);
        Cell headerCell = headerRow.createCell(0);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2));
        headerCell.setCellValue(titleName);
        headerCell.setCellStyle(createTitleStyle(workbook));
        headerRow.setHeightInPoints(30);
        Row normalHeaderRow = sheet.createRow(1);
        normalHeaderRow.setHeightInPoints(25);
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        String[] headers = {"采集时间", "数值", "质控码"};
        for (int i = 0; i < headers.length; i++) {
            Cell cell = normalHeaderRow.createCell(i);
            cell.setCellValue(headers[i]);
            cell.setCellStyle(createHeaderStyle(workbook));
            sheet.setColumnWidth(i, 25 * 256);
            sheet.setDefaultColumnStyle(i, style);
        }
        for (int i = 0; i < exportList.size(); i++) {
            Row dataRow = sheet.createRow(i + 2);
            dataRow.setHeightInPoints(20);
            IotMonitorDataBo iotMonitorDataExport = exportList.get(i);
            dataRow.createCell(0).setCellValue(DateUtils.dateTime(iotMonitorDataExport.getDateTime()));
            dataRow.createCell(1).setCellValue(iotMonitorDataExport.getDoubleValue());
            dataRow.createCell(2).setCellValue(iotMonitorDataExport.getQualityCode());
        }
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        workbook.write(response.getOutputStream());
        workbook.close();
    }

    /**
     * 导出监测数据记录
     *
     * @param response the response
     */
    @PostMapping("/download")
    //    @PreAuthorize("@ss.hasPermi('iot:cmd:query')")
    public void exportZip(HttpServletResponse response, @RequestBody IotMonitorDataExportVo iotMonitorDataExportVo) {

        IotSensorRecordBo IotSensorRecordBo = new IotSensorRecordBo();
        IotSensorRecordBo.setDeviceId(iotMonitorDataExportVo.getDeviceId());
        IotSensorRecordBo.setParams(Map.of("beginTime", iotMonitorDataExportVo.getBeginTime(), "endTime", iotMonitorDataExportVo.getEndTime()));

        List<IotSensorRecordBo> list = iIotSensorRecordService.selectIotSensorRecordList(IotSensorRecordBo);
        if (list.isEmpty()) {
            throw new ServiceException(ErrorCodeEnum.NOEXITS_ERROR.getValue(), ErrorCodeEnum.NOEXITS_ERROR.getKey());
        }
        String fileName = StringUtils.format("{}_{}.zip", "设备ID", iotMonitorDataExportVo.getDeviceId());
        File zipFile = new File(LeChiConfig.getRecordLogPath() + fileName);
        try {
            List<File> fileList = list.stream().map(sensorRecordBo -> new File(sensorRecordBo.getFilepath())).toList();
            ZipUtil.zip(zipFile, false, fileList.toArray(new File[0]));
            response.reset();
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/octet-stream; charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment; filename=" + zipFile.getName());
            BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath()));
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            fis.close();
            IOUtils.write(buffer, response.getOutputStream());
        } catch (Exception e) {
            log.error("下载zip压缩包过程发生异常:", e);
            throw new ServiceException(ErrorCodeEnum.EXPORT_ERROR.getValue(), ErrorCodeEnum.EXPORT_ERROR.getKey());
        } finally {
            zipFile.delete();
        }
    }

    /**
     * 删除监测数据  暂时没有使用
     *
     * @param ids the ids
     * @return the ajax result
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        iotMonitorDataService.deleteIotMonitorDataByIds(ids);
        return AjaxResult.success();
    }
}
